package signfactory

import (
	"fmt"
	"strings"

	"gitee.com/micro-plat/sas/sas/modules/util"
)

//SHA512SignHandler sha256方法
type SHA512SignHandler struct{}

//newSHA512SignHandler 创建对象
func newSHA512SignHandler() *SHA512SignHandler {
	return &SHA512SignHandler{}
}

//Sign 签名
func (o *SHA512SignHandler) Sign(raw, key, sType, rsaHasType string) (sign string) {
	return util.Sha512Encrypt(raw)
}

//Verify 签名认证
func (o *SHA512SignHandler) Verify(outSign, raw, key, sType, rsaHasType string) (res bool, err error) {
	sign := o.Sign(raw, key, sType, rsaHasType)
	res = strings.EqualFold(outSign, sign)
	if res {
		return
	}
	return res, fmt.Errorf("Verify: sign:%s,outSign:%s", sign, outSign)
}
